﻿<MudDataGrid MultiSelection="true" @bind-SelectedItems="_selectedItems"
    ServerData="@(new Func<GridState<Item>, CancellationToken, Task<GridData<Item>>>(ServerReload))">
    <Columns>
        <SelectColumn T="Item" ShowInFooter="true"/>
        <PropertyColumn Property="x => x.Name" />
    </Columns>
</MudDataGrid>

<div>
    @string.Join(",", _selectedItems.Select(x => x.Name))
</div>

@code {
    private HashSet<Item> _selectedItems = [];

    public class Item(string name)
    {
        public string Name { get; set; } = name;
    }

    /// <summary>
    /// Here we simulate getting the data from the server
    /// </summary>
    private static async Task<GridData<Item>> ServerReload(GridState<Item> state, CancellationToken token)
    {
        var letters = "ABC";
        var data = new List<Item>();
        foreach (var c in letters)
        {
            data.Add(new Item(c.ToString()));
        }

        var totalItems = 3;

        return await Task.FromResult(new GridData<Item>() { TotalItems = totalItems, Items = data });
    }    
}
